package acl.action;

import java.util.List;

import acl.bussiness.RoleBusiness;
import acl.hibernate.po.*;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class RoleAction extends ActionSupport {
	private RoleBusiness rbus=new RoleBusiness();
	private List list;
	private String start;
	private OaRoles role;
	public OaRoles getRole() {
		return role;
	}
	public void setRole(OaRoles role) {
		this.role = role;
	}
	public String getStart() {
		return start;
	}
	public void setStart(String start) {
		this.start = start;
	}
	public String getLimit() {
		return limit;
	}
	public void setLimit(String limit) {
		this.limit = limit;
	}
	private String limit;
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	public String rolelist(){
		this.list=rbus.getRoleByPage(Integer.parseInt(start), Integer.parseInt(limit));
		return Action.SUCCESS;
	}
	public String edit(){
		
		return "edit";
	}
	public String saveedit(){
		//角色对象为空或者角色名称未填，保存失败
		if(role==null||role.getRolename().equals(""))
		{
			addActionError(getText("ROLE_NAMEBLANK"));
			return "save";
		}
		/*
		 * 调试状态下，角色的创建人使用默认值
		 */
		role.setUserId(1);
		
		if(rbus.saveOrUpdateRole(role)==true){
			addActionMessage(getText("SAVE_SUCCESS"));
		}
		else
		{
			addActionError(getText("SAVE_FAILED"));
		}
		return "save";
	}
	public String execute() throws Exception{
		String curActName=ActionContext.getContext().getActionInvocation().getProxy().getActionName();
		String[] splitnames=curActName.split("_");
		String targetName="";
		if(splitnames.length>0)
			targetName=splitnames[splitnames.length-1];
		else
			targetName=curActName;
		return targetName;
	}
}
